package com.kyubi.xmlsynth.source;

/**
 * 
 * A class used as a Factory for generating the appropriate DataSource objects.
 * 
 * @author anand
 *
 */
public class SourceFactory {

	/**
	 * Produce the appropriate datasource depending on the file extension.
	 * 
	 * @param filePath	the path of the data source file
	 * @return	the data source object
	 */
	public static IDataSource produceDataSource(String filePath) {
		IDataSource src = null;
		
		String[] tokens = filePath.split("\\.");
		String ext = tokens[tokens.length-1];
		
		if(ext.equalsIgnoreCase("txt")) {
			src = new TextDataSource();
			src.setSource(filePath);
			
			return src;
		} else {
			src = new TextDataSource();
			src.setSource(filePath);
			
			return src;
		}
	}
	
}
